#ifndef _CRC_SOFT_H___
#define _CRC_SOFT_H___
#include "stdint.h"


#ifdef __cplusplus
 extern "C" {
#endif

// #define USE_CRC32
#define USE_CRC16
#define USE_CRC8


#ifdef USE_CRC32
//==============================================================================================
//=============================================CRC32============================================
#pragma pack (4)
#define SUM  1024  //4的整数
typedef struct
{
	unsigned char  SOF;//帧头
	unsigned char  MOD;//(4 - (数据长度%4))
	unsigned short LEN;//数据长度
	unsigned int   CRC32;//CRC32校验码
	unsigned char  DATA[SUM];//数据BUF
}FRAME;

unsigned int CRC_Soft32 (unsigned char* p, unsigned long len);
unsigned int CRC_Soft32Check (unsigned char* p, unsigned long len, uint32_t CRC32Rec);
void UsasrFrameSend(FRAME * pBuffer);
unsigned char UsasrFrameRec(unsigned char * str);
//==============================================================================================
//=============================================CRC32END=========================================
#endif

#ifdef USE_CRC16
//==============================================================================================
//=============================================CRC16============================================
uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC);
uint32_t Verify_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength);
void Append_CRC16_Check_Sum(uint8_t * pchMessage,uint32_t dwLength);
//==============================================================================================
//=============================================CRC16END=========================================
#endif

#ifdef USE_CRC8
//==============================================================================================
//=============================================CRC8=============================================
unsigned char Get_CRC8_Check_Sum(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8);
unsigned int Verify_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
void Append_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
//==============================================================================================
//=============================================CRC8END==========================================
#endif
#ifdef __cplusplus
 }
#endif


#endif

